package designPattern.Observer_delegate;

/**
 * <pre>类名: DefaultDelegation</pre>
 * <pre>描述: 默认委托，提供了默认实现</pre>
 * <pre>版权: web_chen@163.com</pre>
 * <pre>日期: 2020/3/19 14:19</pre>
 * <pre>作者: chenwb</pre>
 */
public abstract class DefaultDelegation {

	private EventHandler eventHandler = new EventHandler();

	/**
	 * @Description: 新增委托
	 * @author chenwb
	 * @date 2020/3/19 13:46
	 * @param target  目标类
	 * @param methodName 目标方法
	 * @param args args 可变入参
	 * @return void
	 */
	public void addListeners(Object target, String methodName, Object... args) {
		eventHandler.addEvent(target, methodName, args);
	}

	/**
	 * @Description: 通知他人
	 * @author chenwb
	 * @date 2020/3/19 14:17
	 * @return void
	 */
	public void notifyOthers() {
		eventHandler.handle();
	}


	/**
	 * 获取eventHandler
	 * @return eventHandler
	 */
	public EventHandler getEventHandler() {
		return eventHandler;
	}

	/**
	 * 设置eventHandler
	 * @param eventHandler eventHandler
	 */
	public void setEventHandler(EventHandler eventHandler) {
		this.eventHandler = eventHandler;
	}
}
